#ifndef DATABASE_H
#define DATABASE_H

#include <QObject>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlIndex>
#include <QDate>
#include <QMap>


class DBTabBase;
class DataBase
{

public:
    const static QLatin1String DATABASE_NAME;
    static QSqlDatabase& getDataBase();
    static DataBase *getObj(){
        static DataBase base;
        return &base;
    }
    DBTabBase *getDBTab(const QLatin1String &tabName){
       auto it = mTabMap.find(tabName);
       if(it!=mTabMap.end()){
           return it.value();
       }
       return NULL;
    }
    int cmpTableVersion(const char *dbname,int ver);

private:

    const static QLatin1String DB_VERSION_NAME;
    QMap<QLatin1String,DBTabBase*> mTabMap;
    explicit DataBase();


    QSqlDatabase mDb;

    void UpdateDataBaseVersion();//数据库修改请放在此函数中修改
    void setDataBaseVersion(int i);
    int getDataBaseVersion();

    bool execRenameTab(const QString &oldname, const QString &newName); //need remove to databsequery

};

#endif // DATABASE_H
